var view = null
var windowWidth = null

//tabcount(一共几个tab), 默认4个
function createView(tabcount, app){
	windowWidth = uni.getSystemInfoSync().windowWidth
	view = new plus.nativeObj.View('test',{bottom:'0px',left:'0px',height:'56px',width:'100%'});
	// 绘制文本
	view.drawRect({color:'rgba(255,200,80,0)', borderWidth:'1px',radius:'0px'},{top:'0px',left:'0px',width:'100%',height:'100%'});
	view.show();
	view.addEventListener("click", function(e){
		var index = getTabIndex(e.clientX, tabcount)
		goTabbar(index, app)
	}, false);
	return view
}
//获取点击tabbar索引
//x(点击x方向位置), tabcount(一共几个tab)
function getTabIndex (x, tabcount){
	tabcount = tabcount || 5
	var itemWidth = windowWidth / tabcount
	tabcount += 1
	var index = 0
	for(var i=1;i<tabcount;i++){
		if(itemWidth * i > x){
			index = i
			break;
		}
	}
	return index - 1
}
//tabbar跳转
function goTabbar (index, app){
	var tabArr = ['/pages/index/index', '/pages/miner/index', '/pages/mall/index',  '/pages/wallet/index',  '/pages/user/index']
	if(index != 2){
		//console.log(index)
		uni.switchTab({
			url: tabArr[index]
		})
	}else{
		if(!app.$store.state.logged){
			if(index == 2){
				let version = uni.getStorageSync('lang') || 'zh-cn';
				if(version == "en-us"){
					plus.nativeUI.toast('Coming soon');	
				}else if(version == "zh-cn"){
					plus.nativeUI.toast('即将开启');	
				}
			}
				
		}else{
			uni.switchTab({
				url: tabArr[index]
			})
			
		}
	}
}

export default createView